# -*- coding: UTF-8 -*-

import os,time
from selenium import  webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.wait import WebDriverWait


chrome=Options()
chrome.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_driver = r"D:\Programs\Python\Python37\chromedriver.exe"   ##驱动对应地址

def logint():
    path=os.path.join('file:///',os.getcwd(),'selenium.html')
    driver=webdriver.Chrome(chrome_driver,chrome_options=chrome)
    driver.get(path)
    time.sleep(2)
    driver.maximize_window()
    driver.find_element_by_css_selector("div#signup input[name='username']").send_keys("rabbit")
    driver.find_element_by_css_selector("div#signup input[name='password']").send_keys("love")
    time.sleep(2)
    driver.find_element_by_css_selector("div#signup input[name='remeber']").click()
    driver.find_element_by_css_selector("div#signup input[name='multi_login']").click()
    choice=driver.find_element_by_css_selector("div#signup select[name='city']")
    Select(choice).select_by_value("sz")
    driver.find_element_by_css_selector("div#signup input[type='submit']").click()
    loctor=(By.CSS_SELECTOR,'div#signup p')
    WebDriverWait(driver,30).until(ec.text_to_be_present_in_element(loctor,'注册成功'))
    resul=driver.find_element_by_css_selector("div#signup p")
    if resul.text=="注册成功":
        print("登录成功")
    else:
        print("登录失败")
    driver.quit()

logint()